package android_fields;

import common.GUIColor;

import android_board.GUICenter;
import android_codebehind.AndroidComponentFactory;
import android_codebehind.GUIPlayer;

public abstract class GUIOwnable extends AndroidField{
	protected String prefix = "";
	protected String postfix = "";
	protected GUIPlayer owner;
	private String leje;
	public GUIOwnable(GUIColor bgColor, GUIColor fgColor, String title,
		String subText, String description, String leje){
		super(bgColor, fgColor, title, subText, description);
		this.leje = leje;
	}
	
	public GUIPlayer getOwner(){return this.owner; }
	public void setOwner(String prefix, GUIPlayer owner, String postfix){
		this.owner = owner;
		this.prefix = prefix;
		this.postfix = postfix;
		if(owner == null){
			AndroidComponentFactory.createLineBorder(this.cell, 2, GUIColor.BLACK.getRGB());
			this.subTextView.setText(this.subText);
		}else{
			GUIColor c1 = this.owner.getPrimaryColor();
			GUIColor c2 = this.owner.getSecondaryColor();
			AndroidComponentFactory.createDashedBorder(this.cell, 4, 10, c1.getRGB(), c2.getRGB());
			String nameToUse = owner.getName();
			nameToUse = (nameToUse.length() > 11) ? nameToUse.substring(0, 8)+"..." : nameToUse;
			this.subTextView.setText(nameToUse);
		}
	}
	public String getLeje(){
		return this.leje;
	}
	
	@Override
	public void displayOnCenter(){
		super.displayOnCenter();
		if(this.owner != null){
			GUIColor c1 = this.owner.getPrimaryColor();
			GUIColor c2 = this.owner.getSecondaryColor();
			AndroidComponentFactory.createDashedBorder(GUICenter.getInstance().getCenterPanel(), 8, 10, c1.getRGB(), c2.getRGB());
			
			GUICenter.divider.setBackgroundColor(c1.getRGB());
		}else{
			AndroidComponentFactory.createLineBorder(GUICenter.getInstance().getCenterPanel(), 4, this.fgColor.getRGB());
		}
	}
}